package com.tangruojie.controller;

import com.tangruojie.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class UserController {

    /**
     * 响应页面：跳转页面
     *
     * @return
     */
    @RequestMapping("/toJumpPage")
    public String toJumpPage() {
        System.out.println("jump page");
        return "page.jsp";
    }

    /**
     * 响应文本字符串
     *
     * @return
     */
    @RequestMapping("/toText")
    @ResponseBody
    public String toText() {
        System.out.println("text");
        return "response text";
    }

    /**
     * 响应POJO对象
     *
     * @return
     */
    @RequestMapping("/toJsonPOJO")
    @ResponseBody
    public User toJsonPOJO() {
        System.out.println("json pojo");
        User user = new User();
        user.setName("tangruojie");
        user.setAge(18);
        return user;
    }

    /**
     * 响应POJO集合对象
     *
     * @return
     */
    @RequestMapping("/toJsonList")
    @ResponseBody
    public List<User> toJsonList() {
        System.out.println("json list");
        User wangchang = new User("wangchang", 20);
        User tangruojie = new User("tangruojie", 18);
        List<User> list = new ArrayList<>();
        list.add(wangchang);
        list.add(tangruojie);
        return list;
    }

}
